<template>
	<view>
		<user-pic :userinfo="userinfo"></user-pic>
		<me-gedan :createList="createList" :collectList="collectList" :navtoUrl="navtoUrl"></me-gedan>
	</view>
</template>

<script>
	import userPic from '../../components/user/user-pic/user-pic.vue';
	import meGedan from '../../components/home/me-gedan/me-gedan.vue'
	export default {
		components:{
			userPic,
			meGedan
		},
		data() {
			return {
				userinfo:{},
				createList:[],
				collectList:[],
				navtoUrl:"../playlist/playlist"
			}
		},
		onLoad(options) {
 			    let uid=options.uid;
			    this.getUserinfo(uid);
			    this.getplaylist(uid);
		},
		methods: {
			async getUserinfo(uid){
			    const result=await this.request({url: this.bsurl+'user/detail?uid='+uid});
			    let {eventCount,follows,followeds,nickname,signature,gender,avatarUrl,backgroundUrl}=result.profile
			    let userinfo={eventCount,follows,followeds,nickname,signature,gender,avatarUrl,backgroundUrl}
			    this.userinfo=userinfo;
				uni.setNavigationBarTitle({
				   title: userinfo.nickname+'的空间' 
				})
			},
			//发送请求
			async getplaylist(uid){
				const result=await this.request({url: this.bsurl+'user/playlist?uid='+uid});
				
				let index =result.playlist.findIndex(v=>{
					return v.userId!=uid;
				})
				const collectList=result.playlist.splice(index).map(v=>{
					return {
						name:v.name,
						id:v.id,
						coverImgUrl:v.coverImgUrl+'?param=80y80',
						trackCount:v.trackCount,
						playCount:v.playCount
					}
				});
				this.collectList=collectList;
				
				const createList=result.playlist.map(v=>{
					return {
						name:v.name,
						id:v.id,
						coverImgUrl:v.coverImgUrl+'?param=50y50',
						trackCount:v.trackCount,
						playCount:v.playCount
					}
				});
				this.createList=createList;			   
			},
			
		}
	}
</script>

<style lang="less" scoped>
	
</style>
